package com.smartHire;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.smartHire.dao.GoodsDao;
import com.smartHire.dao.OrderDao;
import com.smartHire.domain.*;
import com.smartHire.service.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.xml.ws.Service;
import java.awt.*;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class test {

    @Test
    public void testUser()
    {
        String config = "applicationContext.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);

        UserService service = (UserService) ctx.getBean("userService");
        User user = new User();
        user.setU_Id("11223344667");
        user.setName("55655");
        user.setSex("男");
        System.out.println("联合黑啊放大");
        try {
            int nums = service.addUser(user);
        }catch (Exception e)
        {
            e.printStackTrace();
        }


//        Address address = new Address();
//        address.setAddress_Id(1);
//        address.setU_Id("55151");
//        address.setAddress("常州市");
//        address.setPhone_number("122229");
//        address.setName("哈哈哈2323");
//
//        int nums = service.addAddress(address);
//        System.out.println(nums);
//        service.addAddress(address);

    }


    @Test
    public void testBusinessInsert(){

        String config="applicationContext.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
        //获取spring容器中的dao对象
       /* BusinessService service = (BusinessService) ctx.getBean("businessService");
        Business business = new Business();
        business.setB_id("123");
        business.setB_name("哈哈哈哈");
        business.setSex("666");
        try {
            int nums = service.addBusiness(business);
            //spring和mybatis整合在一起使用，事务是自动提交的。 无需执行SqlSession.commit();
            System.out.println("nums="+nums);
        }catch (Exception e)
        {
            e.printStackTrace();
        }*/

//        ShopService shopService = (ShopService) ctx.getBean("shopService");
//        Shop shop = new Shop();
//        shop.setShop_id("aaa");
//        shop.setB_Id("123");
//        shop.setShop_name("六");
//        shop.setShop_address("changzhou");
//
//        shopService.addShop(shop);

        GoodsService goodsService = (GoodsService) ctx.getBean("goodsService");

        for (int i=0; i < 5; i++)
        {
            Goods goods = new Goods();
            goods.setShop_id("aaa");
            goods.setGood_name("" + i);
            goods.setInventory(50);
            goods.setPrice(3.5f);
            goods.setSort("手机");
            goods.setPicture1("手机数码/" + (i+1) + "/1.jpg");
            goods.setPicture2("手机数码/" + (i+1) + "/2.jpg");
            goods.setPicture3("手机数码/" + (i+1) + "/3.jpg");
            goods.setPicture4("手机数码/" + (i+1) + "/4.jpg");
            goods.setAudit("no");

            goodsService.addGoods(goods);
        }



//        List<Goods> goodses = goodsService.queryGoods();
//        System.out.println(goodses);


    }

    @Test
    public void tes2()
    {
        String config="applicationContext.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
        OrderService orderService = (OrderService) ctx.getBean("orderService");
        Order_goodsService order_goodsService = (Order_goodsService) ctx.getBean("order_goodsService");
//
        List orders = orderService.queryOrderByType("1", "ogTuX6L89zC0-pyBchVzD5jCuQmo");

        for (Object a:orders)
        {
            System.out.println(a);
        }






//        GoodsService goodsService = (GoodsService) ctx.getBean("goodsService");
//
//
//        Goods goods = new Goods();
//        goods.setGood_name("雪碧");
//        List<Goods> goodes = goodsService.SearchGoods(goods.getGood_name(), "2");
//        System.out.println(goodes);


    }

    @Test
    public void test1()
    {
//        String config="applicationContext.xml";
//        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
//
//        OrderService orderService = (OrderService) ctx.getBean("orderService");
//
//        List list = orderService.queryOrderByType("1");
//
//        for (Object o:list)
//        {
//            System.out.println(o);
//        }












//
//        OrderDao orderDao = (OrderDao) ctx.getBean("orderDao");
//        int nums = orderDao.queryOrderRows();
//        System.out.println(nums);
//        String str = "1";
//        String str2 = String.format("%05d",1);
//        System.out.println(str2);
//        String str = "{\"nickName\":\"梦日\",\"gender\":1,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"Algeria\",\"avatarUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJaPwtAD4zoKU0HPYoRAqIwg8QByjSkgarkiarv3foauXCx3Kx5B9rdHmd86yQ3mktbTqBsicrdcC8g/132\"}";
////        System.out.println(str);
////        Map maps = (Map)JSONObject.parse(str);
////
////        System.out.println(maps.get("nickName"));
////        System.out.println(maps.get("gender"));

    }

    @Test
    public void testTime()
    {
//        Date date = new Date();
//        date.setTime(date.getTime()+(1000 * 60 * 60 * 24));
//        System.out.println(date);

        String config="applicationContext.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
       ShopService service = (ShopService) ctx.getBean("shopService");

       Shop shop = new Shop();
       shop.setShop_name("为");
       List<Shop> shops = service.searchShop(shop);

       System.out.println(shops);


    }
}

